package com.zzj.web.controller.dusto.bill.detail;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzj.common.core.domain.entity.SysUser;
import com.zzj.web.restfulservice.SellDetailRestfulService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzj.common.annotation.Log;
import com.zzj.common.core.controller.BaseController;
import com.zzj.common.core.domain.AjaxResult;
import com.zzj.common.enums.BusinessType;
import com.zzj.bill.domain.BillSellDetail;
import com.zzj.bill.service.IBillSellDetailService;
import com.zzj.common.utils.poi.ExcelUtil;
import com.zzj.common.core.page.TableDataInfo;

/**
 * 当日销售管理Controller
 *
 * @author zzj
 * @date 2022-01-28
 */
@RestController
@RequestMapping("/bill/detail")
public class BillSellDetailController extends BaseController
{
    @Autowired
    private IBillSellDetailService billSellDetailService;

    @Autowired
    private IBillSellDetailService sellDetailService;


    @Autowired
    private SellDetailRestfulService sellDetailRestfulService;



    /**
     * 查询当日销售管理列表
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(BillSellDetail sellDetail)
    {

        List<BillSellDetail> list =  sellDetailRestfulService.selectByPage(sellDetail);
        List<BillSellDetail> response= sellDetailRestfulService.setValue(list);
        return getDataTable(response);
    }

    /**
     * 导出当日销售管理列表
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:export')")
    @Log(title = "当日销售管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillSellDetail billSellDetail)
    {
        List<BillSellDetail> list = billSellDetailService.selectBillSellDetailList(billSellDetail);
        ExcelUtil<BillSellDetail> util = new ExcelUtil<BillSellDetail>(BillSellDetail.class);
        util.exportExcel(response, list, "当日销售管理数据");
    }

    /**
     * 获取当日销售管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(billSellDetailService.selectBillSellDetailById(id));
    }

    /**
     * 新增当日销售管理
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:add')")
    @Log(title = "当日销售管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BillSellDetail billSellDetail)
    { int insert = sellDetailRestfulService.insert(billSellDetail);
        return toAjax(insert);
    }

    /**
     * 修改当日销售管理
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:edit')")
    @Log(title = "当日销售管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BillSellDetail billSellDetail)
    {
        return toAjax(billSellDetailService.updateBillSellDetail(billSellDetail));
    }

    /**
     * 删除当日销售管理
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:remove')")
    @Log(title = "当日销售管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(billSellDetailService.deleteBillSellDetailByIds(ids));
    }

    /**
     * 入系统
     * @param ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:intoSystem')")
    @Log(title = "sell_detail ", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/intoSystem/{ids}",method = RequestMethod.PUT)
    public AjaxResult intoSystem(@PathVariable("ids") Long[] ids)
    {
        return toAjax(sellDetailService.intoSystemSellDetailByIds(ids));
    }

    /**
     * 取消入系统
     * @param ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('bill:detail:intoSystem')")
    @Log(title = "sell_detail ", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/outSystem/{ids}",method = RequestMethod.PUT)
    public AjaxResult outSystem(@PathVariable("ids") Long[] ids)
    {
        return toAjax(sellDetailService.outSystemSellDetailByIds(ids));
    }

    /**
     * 查询用户接口根据店铺
     */

    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo() {
       List<SysUser> users = sellDetailRestfulService.getUserInfo();
        AjaxResult ajax = AjaxResult.success();
        ajax.put("userInfoList", users);
        return ajax;
    }
}
